package cc.verywell.pureblock.func.node;

import java.nio.ByteBuffer;

import cc.verywell.pureblock.net.Msg;
import cc.verywell.pureblock.net.NormalSession;
import cc.verywell.pureblock.util.StringUtil;

/**
* 报文:
* Node数量[2_bits] Node[?_bits]
* 
* 其它的一切，都应该由继承类书写;
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年3月24日 下午9:21:29
*/
public abstract class NodesMsg implements Msg {

	protected Node[] nodes;
	
	protected void init(Node[] nodes) {
		this.nodes = nodes;
	}
	protected void init(ByteBuffer bb) {
		int len = StringUtil.readLength(2, bb);
		this.nodes = new Node[len];
		for (int i = 0; i < nodes.length; i++) {
			this.nodes[i] = new Node(bb);
		}
	}

	@Override
	public void write(ByteBuffer bb, NormalSession nc) {
		StringUtil.writeLength(2, nodes.length, bb);
		for (Node node : nodes) {
			node.write(bb, nc);
		}
	}

	public Node[] getNodes() {
		return nodes;
	}
	public void setNodes(Node[] nodes) {
		this.nodes = nodes;
	}

}
